'Pineapple Controller Test

'ver 3.0 has GP10 and GP12 reversed
'this will normally be set to 3.1
Const ver = 3.1

SetPin gp2, dout
SetPin gp5, dout
SetPin gp6, dout
SetPin gp8, dout
SetPin gp9, dout
SetPin gp10, dout
SetPin gp13, dout
SetPin gp11, dout
SetPin gp12, dout
SetPin gp14, dout
SetPin gp4, dout
SetPin gp27, dout
SetPin gp15, dout
SetPin gp7, dout
SetPin gp26, din, pullup

SetPin gp29, din, pullup
SetPin gp28, din, pullup
SetPin gp3, din, pullup

pu = 200
pa = 500

s = Timer + 5000
CLS
Do
Text 0,0,Time$,,3
Loop Until Timer > s

CLS
Text 0,0,"Test 1"
Text 0,11,"Press S1",,2
Do While Pin(gp29) = 1
Loop
Text 0,11,"OK      ",,2
Pause 1000
Text 0,11,"Press S2",,2
Do While Pin(gp28) = 1
Loop
Text 0,11,"OK      ",,2
Pause 1000
Text 0,11,"P0ress S3",,2
Do While Pin(gp3) = 1
Loop
Text 0,11,"OK      ",,2
Pause 1000
Text 0,11,"PASSED  ",,2
Pause 3000


test2:
CLS
Text 0,0,"Test 2"
Text 0,11,"S1 if red flash"
Do
 Pin(gp6) = 1
 Pause 400
 Pin(gp6) = 0
 Pause 400
Loop While Pin(gp29) = 1
Text 0,11,"S1 if grn flash"
Do
 Pin(gp5) = 1
 Pause 400
 Pin(gp5) = 0
 Pause 400
Loop While Pin(gp29) = 1
CLS
Text 0,0,"Test 2"
Text 0,11,"PASSED  ",,2
Pause 3000

Pin(gp5) = 1


test3:
CLS
Text 0,0,"Test 3"
Text 0,11,"S1 buzzer test"
Text 0,22,"S2=OK S3=Fail"
Do
  Pin(gp2) = Not(Pin(gp29))
Loop Until Pin(gp28) = 0 Or Pin(gp3) = 0
Pin(gp2) = 0
CLS
Text 0,0,"Test 3"
If Pin(gp28) = 0 Then
  Text 0,11,"PASSED  ",,2
Else
 Text 0,11,"FAILED   ",,2
EndIf
Pause 3000


test4:
CLS
Text 0,0,"Test 4"
Text 0,11,"S1 select relay"
Text 0,22,"S2=tog S3=exit"
n=0
Do
  If Pin(gp29) = 0 Then
    n=n+(n<3)
    If n=3 Then n=0
    Do :Loop Until Pin(gp29) = 1
  EndIf
  Select Case n
  Case 0
    Text 64,0,"AC1"
  Case 1
    Text 64,0,"AC2"
  Case 2
    Text 64,0,"AC3"
  End Select
  If Pin(gp28) = 0 Then
    Select Case n
    Case 0
      Pin(gp27) = Not(Pin(gp27))
    Case 1
      Pin(gp15) = Not(Pin(gp15))
    Case 2
      Pin(gp7) = Not(Pin(gp7))
    End Select
    Do : Loop Until Pin(gp28) = 1
  EndIf
Loop Until Pin(gp3) = 0
Pause 3000

test5:
CLS
Text 0,0,"Test 5"
Text 0,11,"S1 select DC out"
Text 0,22,"S2=tog S3=exit"
n=0
Do
  If Pin(gp29) = 0 Then
    n=n+(n<3)
    If n=3 Then n=0
    Do :Loop Until Pin(gp29) = 1
  EndIf
  Select Case n
  Case 0
    Text 64,0,"DC1"
  Case 1
    Text 64,0,"DC2"
  Case 2
    Text 64,0,"DC3"
  End Select
  If Pin(gp28) = 0 Then
    Select Case n
    Case 0
      Pin(gp8) = Not(Pin(gp8))
    Case 1
      Pin(gp9) = Not(Pin(gp9))
    Case 2
      Pin(gp4) = Not(Pin(gp4))
    End Select
    Do : Loop Until Pin(gp28) = 1
  EndIf
Loop Until Pin(gp3) = 0
Pause 3000


test6:
CLS
Text 0,0,"Test 6"
Text 0,11,"S1 WS/RGB"
Text 0,22,"S2=start S3=exit"
n = 0
Do
  If Pin(gp29) = 0 Then
    n = Not n
    Do : Loop Until Pin(gp29) = 1
  EndIf
  If n = 0 Then Text 64,0,"WS " Else Text 64,0,"RGB"
  If Pin(gp3) = 0 Then GoTo test6x
Loop Until Pin(gp28) = 0
Do : Loop Until Pin(gp28) = 1
Select Case n
  Case 0 'tests for WS outputs
    CLS
    Text 0,0,"Test 6"
    Text 0,11,"S1=R  S2=B"
    Text 0,22,"S3= exit"
    Do
      If Pin(gp29) = 0 Then
        If ver = 3.0 Then
          Pin(gp10) = Not Pin(gp10)
        Else
          Pin(gp12) = Not Pin(gp12)
        EndIf
        Do : Loop Until Pin(gp29) = 1
      EndIf
      If Pin(gp28) = 0 Then
        Pin(gp13) = Not Pin(gp13)
        Do : Loop Until Pin(gp28) = 1
      EndIf
    Loop Until Pin(gp3) = 0
  Case 1 'tests for RGB outputs
    CLS
    Text 0,0,"Test 6"
    Text 0,11,"S1=Sel  S2=tog"
    Text 0,22,"S3= exit"
    j=0
    Do
      If Pin(gp29) = 0 Then
      j=j+(j<3)
      If j=3 Then j=0
      Do :Loop Until Pin(gp29) = 1
    EndIf
    Select Case j
    Case 0
      Text 64,0,"Red "
    Case 1
      Text 64,0,"Grn"
    Case 2
      Text 64,0,"Blue"
    End Select
    If Pin(gp28) = 0 Then
      Select Case j
      Case 0
        Pin(gp11) = Not(Pin(gp11))
      Case 1
        If ver = 3.0 Then
          Pin(gp12) = Not(Pin(gp12))
        Else
          Pin(gp10) = Not(Pin(gp10))
        EndIf
      Case 2
        Pin(gp14) = Not(Pin(gp14))
      End Select
      Do : Loop Until Pin(gp28) = 1
    EndIf
    Loop Until Pin(gp3) = 0
End Select
test6x:
Pause 3000


test7:
CLS
Text 0,0,"Test 7"
Text 0,11,"Link temp sensor"
Text 0,22,"D-GND S3=exit"
Do
  Pin(gp6) = Not Pin(gp26)
Loop Until Pin(gp3) = 0
Do : Loop Until Pin(gp26) = 1
Pin(gp6) = 0
Pause 3000

CLS
Text 0,0,"All Tests"
Text 0,11,"COMPLETED",,2
End

                                      